
#include "Base.h"
#include "IEffect.h"
#include "Graphics\Model\Model.h"
#include "IEffectPass.h"
#include "Maths\Matrix4.h"

namespace CasaEngine
{

	/**
	 *
	 */
	IEffect::IEffect()
	{
		m_Passes.reserve(1);
	}

	/**
	 *
	 */
	IEffect::~IEffect()
	{
	}

	/**
	 * 
	 */
	void IEffect::Draw(Model *pModel, const Matrix4 &viewProjModelMat_)
	{
		//Material *pMaterial = pModel->GetMaterial();
		//Matrix4 modelViewProj = pModel->GetTransform()->GetViewMatrix();

		Begin();

		//(*it)->pEffect->SetParameter("ModelViewProj", pCamera->GetViewMatrix() * (*it)->pMatWorld);
		//SetParameter();

		std::vector<IEffectPass *>::iterator it;

		for (it = m_Passes.begin();
			it != m_Passes.end();
			it++)
		{
			(*it)->Begin();
			pModel->PreRender(*it, viewProjModelMat_);
			pModel->Render();
			(*it)->End();
		}

		End();
	}

	/**
	 * 
	 */
	std::vector<IEffectPass *>::iterator IEffect::PassesBeginIterator()
	{
		return m_Passes.begin();
	}

	/**
	 * 
	 */
	std::vector<IEffectPass *>::iterator IEffect::PassesEndIterator()
	{
		return m_Passes.end();
	}

	/**
	 * 
	 */	
	void IEffect::AddPass(IEffectPass *pPass_ )
	{
		m_Passes.push_back(pPass_);
	}

} // namespace CasaEngine
